package vip.aning.gitsync.data;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import vip.aning.gitsync.constant.AppConst.MsgType;

public class SyncMessageListData {
    /**
     * listciew数据
     */
    public static ObservableList<String> dataList = FXCollections.observableArrayList();

    public static void add(MsgType type, String msg) {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                String data;
                if (dataList.size() > 100) {
                    dataList.remove(0);
                }
                data = switch (type) {
                    case PULL -> "Pull: " + msg;
                    case PUSH -> "Push: " + msg;
                    case ERROR -> "Error: " + msg;
                    default -> "Log：" + msg;
                };
                dataList.add(data);
            }
        });
    }

    public static void clean() {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                dataList.clear();
            }
        });
    }

}
